package logic

import (
	"commerci/commercirpc/commercirpc"
	"commerci/commercirpc/internal/svc"
	"commerci/moddel/mysql"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsAddLogic) GoodsAdd(in *commercirpc.GoodsAddRequest) (*commercirpc.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line

	good := mysql.Goods{
		Name:   in.Name,
		Price:  in.Price,
		State:  in.State,
		UserId: in.UserId,
	}
	err := good.GoodAdd(mysql.DB)
	if err != nil {
		return nil, err
	}

	return &commercirpc.GoodsAddResponse{
		GoodId: int64(good.ID),
	}, nil
}
